#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        vector<int> state(5);
        int ans = 0;
        for (char& c : croakOfFrogs) {
            switch (c) {
                case 'c':
                    if (state[4] > 0) {
                        state[4]--;
                    } else {
                        ans++;
                    }
                    state[0]++;
                    break;
                case 'r':
                    state[0]--;
                    state[1]++;
                    break;
                case 'o':
                    state[1]--;
                    state[2]++;
                    break;
                case 'a':
                    state[2]--;
                    state[3]++;
                    break;
                case 'k':
                    state[3]--;
                    state[4]++;
                default:
                    break;
            }
            if (state[0] < 0 || state[1] < 0 || state[2] < 0 || state[3] < 0) {
                break;
            }
        }
        if (state[0] != 0 || state[1] != 0 || state[2] != 0 || state[3] != 0) {
            return -1;
        }
        return ans;
    }
};